package javawork;
public class section6_14 {
    // 计算m(i)的值
    public static double calculateMI(int i) {
        double sum = 0.0;
        for (int k = 1; k <= i; k++) {
            // 计算每一项的符号：(-1)^(k+1)
            int sign = (k % 2 == 1) ? 1 : -1;
            // 计算每一项的值并加到总和中
            sum += sign / (double)(2 * k - 1);
        }
        // 乘以4得到m(i)
        return 4 * sum;
    }
    
    public static void main(String[] args) {
        // 打印表格标题
        System.out.println("i\tm(i)");
        // 计算并打印指定i值对应的m(i)，保留4位小数
        for (int i = 1; i <= 901; i += 100) {
            double result = calculateMI(i);
            System.out.printf("%d\t%.4f%n", i, result);
        }
    }
}
    